package main.com.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class MyConnection {
    //用户名
	private final static String user = "root";
	//密码
	private final static String password = "root";
	//驱动
	private final static String driver = "com.mysql.jdbc.Driver";
	//url
	private final static String url = "jdbc:mysql://127.0.0.1:3306/ssh";
	//数据库对象
	private  Connection conn = null;
	//静态代码块
	static {  
        try {  
            // 加载数据库驱动程序  
            Class.forName(driver);  
        } catch (ClassNotFoundException e) {  
            System.out.println("加载驱动错误");  
            System.out.println(e.getMessage());  
        }  
    }  
	
	public Connection open(){
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url, user, password);
			return conn;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	

} 
